﻿define("ow-epi-videocloud/BrowserDialog", [
"epi",
"dojo",
"dojo/_base/lang",

"dijit",
"epi/shell/widget/dialog/Dialog",
"ow-epi-videocloud/BrowserWidget"
],

function (
    epi,
    dojo,
    lang,
    dijit,
    Dialog,
    BrowserWidget) {

    return dojo.declare("ow-epi-videocloud.BrowserDialog", Dialog, {

        defaultActionsVisible: false,

        _browserWidget: null,

        baseClass: 'browser-dialog',

        postMixInProperties: function () {
            this.inherited(arguments);
            this.buttonCancel = epi.resources.action.close;
        },

        postCreate: function () {
            this.inherited(arguments);

            this.set("title", 'Brightcove VideoCloud Browser');
            dojo.style(this.domNode, { width: "800px", height: "", top: "194px" });
        },

        _ensureBrowserWidget: function () {
            if (this._browserWidget) {
                return;
            }
            
            this._browserWidget = new BrowserWidget({
                fileControllerUrl: this.fileControllerUrl,
                selectedVideoId: this.selectedVideoId,
                players: this.players
            });
            
            this.set("content", this._browserWidget);

            // change the height here, to prevent dojo dialog from overriding it
            dojo.style(this.containerNode, { height: "500px" });
        },

        show: function () {
            this.inherited(arguments);

            this._ensureBrowserWidget();
        },

        uninitialize: function () {
            if (this._browserWidget != null) {
                this._browserWidget.destroyRecursive();
            }
            this.inherited(arguments);
        },

        getActions: function () {
            var buttons = [{
                name: this._okButtonName,
                label: this.confirmActionText,
                title: null,
                settings: { "class": "Salt" },
                action: lang.hitch(this, this._onConfirm)
            },
                {
                    name: this._cancelButtonName,
                    label: this.cancelActionText,
                    title: null,
                    action: lang.hitch(this, this._onCancel)
                },
                {
                    name: '_clearButton',
                    label: 'Clear',
                    title: null,
                    action: lang.hitch(this, this._onClear)
                }];

            return buttons;
        },

        _onConfirm: function () {
            this.hide();

            this.onCallback({
                closeAction: 'insert',
                item: this._browserWidget.selectedItem
            });
        },

        _onCancel: function () {
            this.hide();
            this.onCallback(null);
        },

        _onClear: function () {
            this.hide();
            this.onCallback({
                closeAction: 'clear',
                item: []
            });
        },

        onCallback: function(value) {
            
        }
    });
});